package com.ssm.modules.controller;

import com.ssm.modules.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class IndexContoller {

    /**
     *  根据角色跳转到对应首页
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String toIndex(HttpServletRequest request,
                               HttpServletResponse response) throws IOException {
        User user = (User) request.getSession().getAttribute("user");
        // 判断是否是管理员权限
        if(user == null){
            return "redirect:/login";
        }
        // 跳转到管理员首页
        else if("管理员".equals(user.getRole().getName())) {
            return "index_admin";
        }
        // 跳转到学生首页
        else if("学生".equals(user.getRole().getName())) {
            return "index_stu";
        }
        // 跳转到教师首页
        else if("教师".equals(user.getRole().getName())) {
            return "index_tea";
        }
        else {
            return "error/403";
        }
    }


}
